package com.bringway.p2p.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.global.service.SysAttechmentService;
import com.bringway.p2p.service.JkxxService;

/*
* @author 作者 hc
* @version 创建时间：2016年2月1日 上午10:46:55
* 类说明:业务功能-附件管理
*/

@Controller
@RequestMapping("/jkxx")
public class JkxxController extends JsonController{

	@Autowired
	private JkxxService jkxxService;

	
	@Autowired
	private SysAttechmentService attechmentService;
	
	
	@RequestMapping("/queryJkxxList")
	public ModelAndView queryJkxxList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		Integer page = RequestUtils.getIntParameter(request, "page");
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String jkqx = RequestUtils.getStringParameter(request, "jkqx");
		String jkbt = RequestUtils.getStringParameter(request, "jkbt");
		String username = RequestUtils.getStringParameter(request, "username");
		String sjhm = RequestUtils.getStringParameter(request, "sjhm");
		if (null!=page) {
			if (null!=page) {//新版本,传参
				start=(page-1)*limit;
			}
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("jkqx", jkqx);
		params.put("jkbt", jkbt);
		params.put("username", username);
		params.put("sjhm", sjhm);
		
		List list = jkxxService.queryJkxxList(params);
		int count = jkxxService.getJkxxCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
			
		}
		serialize(request,response,result);
		return null;
	}
	
	@RequestMapping("/queryAddList")
	public ModelAndView onAddJkxx(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		
		String jkje = RequestUtils.getStringParameter(request, "jkje");
		String jkqx = RequestUtils.getStringParameter(request, "jkqx");
		String yhke = RequestUtils.getStringParameter(request, "yhke");
		String qcfwf = RequestUtils.getStringParameter(request, "qcfwf");
		String jkyt = RequestUtils.getStringParameter(request, "jkyt");
		String jkbt = RequestUtils.getStringParameter(request, "jkbt");
		String jkms = RequestUtils.getStringParameter(request, "jkms");
		String username = RequestUtils.getStringParameter(request, "username");
		String sqrq = RequestUtils.getStringParameter(request, "sqrq");
		String sjhm = RequestUtils.getStringParameter(request, "sjhm");

		
		params.put("jkje", jkje);
		params.put("jkqx", jkqx);
		params.put("yhke", yhke);
		params.put("qcfwf", qcfwf);
		params.put("jkyt", jkyt);
		params.put("jkbt", jkbt);
		params.put("jkms", jkms);
		params.put("username", username);
		params.put("sqrq", sqrq);
		params.put("sjhm", sjhm);
			
		
		
		jkxxService.onAddJkxx(params);
		result.put("success", true);
		result.put("isAddSuc", true);
		serialize(request,response,result);
		return null;
	}
}
